

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Core;
using JTC.MiniCommerce.Store.Web.Controls;
using JTC.MiniCommerce.Store;
using JTC.MiniCommerce.Core.Configuration;
using JTC.MiniCommerce.Localization;

namespace JTC.MiniCommerce.Web.admin.controls.sitesettings {
  public class SiteSettingsControl : AdminControl {

    #region Member Variables

    private SiteSettings _siteSettings;

    #endregion

    #region Properties

    /// <summary>
    /// Gets the panel.
    /// </summary>
    /// <value>The panel.</value>
    public Panel Panel {
      get {
        return this.FindControl("pnlSettings") as Panel;
      }
    }

    /// <summary>
    /// Gets or sets the site settings.
    /// </summary>
    /// <value>The site settings.</value>
    public SiteSettings SiteSettings {
      get {
        return _siteSettings;
      }
      set {
        _siteSettings = value;
      }
    }

    #endregion

    #region Methods

    #region Public

    /// <summary>
    /// Saves the specified site settings.
    /// </summary>
    /// <param name="siteSettings">The site settings.</param>
    public void Save(SiteSettings siteSettings) {
      try {
        DatabaseConfigurationProvider databaseConfigurationProvider = new DatabaseConfigurationProvider();
        int id = databaseConfigurationProvider.SaveConfiguration(SiteSettings.SECTION_NAME, siteSettings, WebUtility.GetUserName());
        if (id > 0) {
          MasterPage.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblSiteSettingsSaved"));
        }
        else {
          MasterPage.MessageCenter.DisplayFailureMessage(LocalizationUtility.GetText("lblSiteSettingsNotSaved"));
        }
      }
      catch(Exception ex) {
        Logger.Error("Save", ex);
        MasterPage.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
      }
    }

    #endregion

    #endregion

  }
}
